package com.example.demo.config;

import com.example.demo.interceptor.UserLoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chen huilong
 * @data 2022/10/19
 */
@Configuration
public class LoginConfig implements WebMvcConfigurer {

    @Bean
    public UserLoginInterceptor loginInterceptor() {
        return new UserLoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 放行路径
        List<String> patterns = new ArrayList();
        patterns.add("/swagger-ui.html");
        patterns.add("/demo/user/login");
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/**")
                .excludePathPatterns(patterns);
    }
}

